package com.xssn.fjnd.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xssn.fjnd.entities.SysUser;
import com.xssn.fjnd.entities.User;
import com.xssn.fjnd.user.mapper.UserMapper;
import com.xssn.fjnd.user.req.Vo.WxUserLoginVo;
import com.xssn.fjnd.user.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author 线狮少年
 * @since 2023-08-16
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Override
    public User getUserByOpenId(String openid) {
        User user = baseMapper.selectOne(
                new LambdaQueryWrapper<User>().eq(User::getOpenId, openid)
        );
        return user;
    }

    @Override
    public WxUserLoginVo getUserLoginVo(Long id) {
        User user = baseMapper.selectById(id);
        WxUserLoginVo userLoginVo = new WxUserLoginVo();
        userLoginVo.setUserId(id);
        userLoginVo.setNickName(user.getNickName());
        userLoginVo.setAvatar(user.getAvatar());
        userLoginVo.setIsNew(user.getIsNew());
        userLoginVo.setOpenId(user.getOpenId());


        return userLoginVo;
    }


}
